package com.lz.sports.ui.group

import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavController
import androidx.navigation.findNavController
import com.lz.comm.BR
import com.lz.library.base.BaseActivity
import com.lz.library.extension.click
import com.lz.sports.R
import com.lz.sports.databinding.ActDeviceGroupBinding
import com.lz.sports.vm.group.DeviceGroupViewModel
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch

//设备分组
class DeviceGroupActivity : BaseActivity<DeviceGroupViewModel, ActDeviceGroupBinding>() {

    lateinit var navController: NavController

    override fun getLayoutRes(): Int = R.layout.act_device_group

    override fun getVMVariableId(): Int = BR.vm

    override fun initData(savedState: Bundle?) {
        navController = findNavController(R.id.nav_group)
        lifecycleScope.launch {
            binding.ivBack.click().collect {
                if (!navController.popBackStack()) finish()
            }
        }
        navController.addOnDestinationChangedListener {_, destination, _ -> viewModel.label.value = destination.label}
    }
}